package com.yeswater.multithread.chapter1.test1_11.test1;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * author : yeswater
 * date : 2023/10/18
 */

public class Run {
    @Test
    public void test1() throws InterruptedException {
        MyThread thread = new MyThread();
        thread.start();
        TimeUnit.SECONDS.sleep(2);
        thread.interrupt();
        System.out.println("z z z z z z");
    }

    @Test
    public void test2() {
        try {
            MyThread thread = new MyThread();
            thread.start();
            TimeUnit.SECONDS.sleep(1);
            thread.interrupt();
            System.out.println(" 是否停止 1 ? =" + thread.isInterrupted());
            System.out.println(" 是否停止 2 ? =" + thread.isInterrupted());
        } catch (InterruptedException e) {
            System.out.println("test2 catch");
            e.printStackTrace();
        }
        System.out.println("end!");
    }

    public static void main(String[] args) {
        Thread.currentThread().interrupt();
        System.out.println(" 是否停止 1 ? =" + Thread.interrupted());
        System.out.println(" 是否停止 2 ? =" + Thread.interrupted());
        System.out.println("end!");
    }
}
